import java.util.Stack;

public class Test {

    public static int calculate(String s) {

        char op = '+';
        Stack<Integer> stack = new Stack<>();
        for(int i = 0;i<s.length();){
            if(s.charAt(i)==' '){
                i++;
            }
            else if(s.charAt(i)>='0'&&s.charAt(i)<='9'){
                int tmp = 0;
                while(i<s.length()&&s.charAt(i)>='0'&&s.charAt(i)<='9'){
                    tmp=tmp*10+Integer.valueOf(s.charAt(i)-'0');
                    i++;
                }
                if(op=='+'){
                    stack.push(tmp);
                }
                if(op=='-'){
                    stack.push(-tmp);
                }
                if(op=='*'){
                    int a = stack.pop();
                    stack.push(a*tmp);
                }
                if(op=='/'){
                    int a = stack.pop();
                    stack.push(a/tmp);
                }

            }else{
                op=s.charAt(i);
                i++;
            }

        }
        int ret = 0;
        while(!stack.isEmpty()){
            ret+=stack.pop();
        }
        return ret;
    }
    public static void main(String[] args) {
     int a = calculate("3+2*2");
        System.out.println(a);
        StringBuilder stringBuilder = new StringBuilder();


    }
}
